//
//  MainViewController.swift
//  Weibo
//
//  Created by 付启刚 on 15/12/12.
//  Copyright © 2015年 faq. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
let mainTabBar = MainTabBar()
    override func viewDidLoad() {
        super.viewDidLoad()
//        tabbar是只读(计算存储)属性,不能够直接进行设置,可以使用KVC进行赋值
        mainTabBar.composeBtn.addTarget(self, action: "composeBtnDidClick", forControlEvents: UIControlEvents.TouchUpInside)
        setValue(mainTabBar, forKey: "tabBar")
        //添加子视图
        addChildViewControllers()
    }
   @objc private func composeBtnDidClick(){
   print(__FUNCTION__)
    let compose=ComposeViewController()
    let nav=UINavigationController(rootViewController: compose)
    //modal页面
    presentViewController(nav, animated: true, completion: nil)
}
    private func addChildViewControllers() {
        self.tabBar.tintColor=themeColor
         addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
          addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
          addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
          addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
    }
    private func addChildViewController(vc: UIViewController,title:String,imageName:String) {
        //根(root)控制器就是显示出来的控制器
        let nav=UINavigationController(rootViewController: vc)
        vc.title=title
        vc.tabBarItem.image=UIImage(named: imageName)
        self.addChildViewController(nav)
    }
}
